﻿using System;
using Autodesk.Revit.DB;
using HYCodeBase.Math;
using HYRevitCode.XYZUtility;

namespace HYRevitCode.CurveUtility
{
	public static class CurveUtilityMethod
	{
		public static Curve GetUnBoundCurve(Curve input)
		{
			if (null == input || !input.IsBound)
			{
				return input;
			}
			Curve curve = input.Clone();
			curve.MakeUnbound();
			return curve;
		}

		public static bool IfPointOnCurve(Curve inputCurve, XYZ inputPoint, bool ifBound = true)
		{
			if (null == inputCurve || inputPoint == null)
			{
				return false;
			}
			Curve curve = inputCurve.Clone();
			if (curve.IsBound)
			{
				curve.MakeUnbound();
			}
			XYZ xyzpoint = inputCurve.Project(inputPoint).XYZPoint;
			XYZ xyzpoint2 = curve.Project(inputPoint).XYZPoint;
			return inputPoint.IsAlmostEqualTo(xyzpoint, MathUtility.GetPrecision(3)) && inputPoint.IsAlmostEqualTo(xyzpoint2, MathUtility.GetPrecision(3));
		}

		public static bool IfTwoBoundLineIsSameLine(Line inputOne, Line inputTwo)
		{
			return XYZUtilityMethod.Is_Points_Collinear(inputOne.GetEndPoint(0), inputOne.GetEndPoint(1), inputTwo.GetEndPoint(0), 1E-09) && XYZUtilityMethod.Is_Points_Collinear(inputOne.GetEndPoint(0), inputOne.GetEndPoint(1), inputTwo.GetEndPoint(1), 1E-09);
		}
	}
}
